﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Snake.Core;
using Snake.Mapping;
using Snake.SQL;

namespace Snake
{
    public abstract class QueryFactory
    {
        private readonly MappingBuilder _builder = new MappingBuilder();
        private IEnumerable<EntityMap> _entities;

        public ISession CreateQuery(string connectionString)
        {
           if(_entities == null)
           {
               OnMapping(_builder);
               _entities = _builder.Build();
           }
           IDbConnection connection = new SqlConnection(connectionString);
           return new Session(_entities, connection);
        }

        protected abstract void OnMapping(IMappingBuilder builder);
    }
}
